<template>
	<view style="padding-bottom: 50px;
		    background: #fff;">
		<view class="toutou">
			<view class="z-tou">
				<view class="" style="display: flex;align-items: center;">
					<text class="zhiz">{{zhidetail.job_name}}</text>
					<text style="width: 60upx;height: 36upx;font-size: 24upx;background-color: #2687FF;color: #fff;display: inline-block;text-align: center;line-height: 36upx;margin-left: 17upx;border-radius: 5upx;"
						v-if="zhidetail.job_type==1">校招</text>
					<text v-else
						style="width: 60upx;height: 36upx;font-size: 24upx;background-color: #FFC600;color: #fff;display: inline-block;text-align: center;line-height: 36upx;margin-left: 17upx;border-radius: 5upx;">社招</text>

				</view>
				<text>{{zhidetail.min_salary}}k-{{zhidetail.max_salary}}k</text>
			</view>
			<view class="tou-j">
				<text style="padding-left: 5upx;">{{zhidetail.work_address}}</text>
				<text>{{zhidetail.year}}</text>
				<text>{{zhidetail.cate_name}}</text>
			</view>
		</view>
		<view class="gs-log" @click="toshop(zhidetail.shop_id)">
			<image :src="zhidetail.logo" mode="" style="width: 100upx;height: 100upx;border-radius: 50%;"></image>
			<text>{{zhidetail.shop_name}}</text>
		</view>
		<view class="leix">
			<text class="zhiz">职位类型</text>
			<text class="lei">{{zhidetail.jobtype_name}}</text>
		</view>
		<view class="leix">
			<text class="zhiz">福利待遇</text>
			<view class="" style="display: flex;flex-wrap: wrap;align-items: center;">
				<text class="lei" v-for="item in zhidetail.welfares" style="margin-right: 10upx;">{{item}}</text>
			</view>
		</view>
		<view class="leix">
			<text class="zhiz">职位描述</text>
			<text style="display: inline-block;margin-top: 30upx;padding-left: 5upx;">{{zhidetail.desc}}</text>
		</view>
		<view class="toud" @click.prevent.stop="toudi(zhidetail)" v-if="zhidetail.is_send == 0">
			投递简历
		</view>
		<view class="touds" v-else>
			已投递
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				zhidetail: {},
				userInfos: {}
			}
		},
		onLoad(option) {
			try {
				const value = uni.getStorageSync('userInfo');
				if (value) {
					this.userInfos = JSON.parse(value)
				}
			} catch (e) {
				// error
			}
			uni.request({
				url: 'https://dsx.cdzer.com/api/Job/job_details', //仅为示例，并非真实接口地址。
				method: 'POST',
				data: {
					job_id: option.id,
					uid: this.userInfos.id,
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded',
				},
				success: (res) => {
					console.log(res, "职位详情")
					this.zhidetail = res.data.data
				}
			});
		},
		methods: {
			toudi(item) {
				if (JSON.stringify(this.userInfos) == '{}') {
					uni.showModal({

						title: '提示',

						content: "你还未登录，是否前往登录页面",

						success: function(res) {

							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pagesB/login/login'
								})
							} else if (res.cancel) {

								console.log('用户点击取消');

							}

						}

					});
				} else if (this.userInfos.shop_id > 0) {
					var that = this
					uni.showModal({

						title: '提示',

						content: "商家无法投递简历",

						success: function(res) {

							if (res.confirm) {
								console.log('用户点击确定');

							} else if (res.cancel) {

								console.log('用户点击取消');

							}

						}

					});
				} else {
					uni.request({
						url: 'http://dsx.cdzer.com/api/Job/apply_job', //仅为示例，并非真实接口地址。
						method: 'POST',
						data: {
							job_id: item.id,
							shop_id: item.shop_id,
							uid: this.userInfos.id
						},
						header: {
							'content-type': 'application/x-www-form-urlencoded',
						},
						success: (res) => {
							console.log(res, "投递")
							if (res.data.status == 200) {
								uni.request({
									url: 'https://dsx.cdzer.com/api/Job/job_details', //仅为示例，并非真实接口地址。
									method: 'POST',
									data: {
										job_id: item.id,
										uid: this.userInfos.id,
									},
									header: {
										'content-type': 'application/x-www-form-urlencoded',
									},
									success: (res) => {
										console.log(res, "职位详情")
										this.zhidetail = res.data.data
									}
								});
								uni.showToast({
									title: res.data.mess,
									icon: 'none'
								})
								this.szh()
							} else {
								var that = this
								uni.showModal({

									title: '提示',

									content: "是否前往个人中心完善简历信息",

									success: function(res) {

										if (res.confirm) {
											uni.switchTab({
												url: '/pages/tabBar/mydetail'
											})
											console.log('用户点击确定');

										} else if (res.cancel) {

											console.log('用户点击取消');

										}

									}

								});
							}
						}
					});
				}
			},
			toshop(id) {
				uni.navigateTo({
					url: `/pagesC/home/personage/personage?userId=${id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	page {}

	.toud {
		width: 690upx;
		height: 88upx;
		line-height: 88upx;
		color: #fff;
		background: #FF3D3D;
		border-radius: 10upx;
		margin: 0 auto;
		margin-top: 120upx;
		text-align: center;
		font-size: 32upx;
	}

	.touds {
		width: 690upx;
		height: 88upx;
		line-height: 88upx;
		color: #FFFFFF;
		background-color: #F5F5F5;
		border-radius: 10upx;
		margin: 0 auto;
		margin-top: 120upx;
		text-align: center;
		font-size: 32upx;
	}

	.zhiz {
		padding-left: 5upx;
		font-size: 30upx;
		color: #000;
		font-weight: 550;
	}

	.leix {
		padding: 30upx;
		display: flex;
		flex-direction: column;

		.lei {
			width: 140upx;
			height: 50upx;
			background: #F5F5F5;
			text-align: center;
			line-height: 50upx;
			display: inline-block;
			margin-top: 30upx;
			padding-left: 20upx;
			padding-right: 20upx;
		}
	}

	uni-page-body {
		background: #fff;
	}

	.gs-log {
		padding: 30upx;
		display: flex;
		align-items: center;
		border-bottom: 2upx solid #EEEEEE;

		text {
			font-size: 30upx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #333333;
			padding-left: 20upx;
		}
	}

	.toutou {
		padding: 40upx 30upx;
		border-bottom: 2upx solid #EEEEEE;

		.z-tou {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.tou-j {
			padding-top: 20upx;

			text {
				font-size: 24upx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				padding-left: 40upx;
				color: #999999;
			}
		}
	}
</style>
